package Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import persistent.dao.ForumDAO;
import persistent.impl.ForumDAOImpl;
import model.TForum;
import Util.SendRequest;

public class EdiForumCtrServlet extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String titleid=request.getParameter("titleid");
		if(titleid==null||titleid.equals("")){
			TForum forum=new TForum();
			request.setAttribute("forum", forum);
		}else{
			int id=Integer.parseInt(titleid);
			ForumDAO fDao=new ForumDAOImpl();
			TForum forum=fDao.getForumById(id);
			
			request.setAttribute("forum", forum);
		}
		
		SendRequest.sendDispatcherForward("editforum.jsp", request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
